package com.quartz.monitor4job.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.quartz.monitor4job.dao.mapper.QuartzLogMapper;
import com.quartz.monitor4job.model.QuartzLog;
import com.quartz.monitor4job.service.QuartzLogService;
import com.quartz.monitor4job.util.QuartzUtils;
/**
 * 
 * @author LIPENG
 *
 * @date 2017年5月5日 上午11:45:36
 *
 * @version V1.0
 */
@Service("quartzLogService")
public class QuartzLogServiceImpl implements QuartzLogService {
    
	@Resource
    private QuartzLogMapper quartzLogMapper;


    @Override
    public QuartzLog insert(String jobName) {
       QuartzLog quartzLog=new QuartzLog();
       quartzLog.setJobName(jobName);
       quartzLog.setJobStartTime(QuartzUtils.getDateStr(new Date()));
       quartzLog.setAddress(QuartzUtils.getHostIp());
       quartzLog.setHostName(QuartzUtils.getHostName());
       quartzLog.setThreadId(String.valueOf(Thread.currentThread().getId()));
       quartzLog.setThreadName(Thread.currentThread().getName());
       insert(quartzLog);
       return quartzLog;
    }
    

    @Override
    public void insert(QuartzLog quartzLog) {
        quartzLogMapper.insert(quartzLog);
    }
    

    @Override
    public QuartzLog find(QuartzLog quartzLog) {
        return quartzLogMapper.find(quartzLog);
    }
    

    @Override
    public void update(QuartzLog quartzLog) {
        quartzLog.setJobEndTime(QuartzUtils.getDateStr(new Date()));
        quartzLogMapper.update(quartzLog);
    }
    

    @Override
    public void updateUnStop() {
        quartzLogMapper.updateUnStop();
    }
    

    @Override
    public List<QuartzLog> list(QuartzLog quartzLog) {
        return quartzLogMapper.list(quartzLog);
    }
    

    @Override
    public void delete(int keepDay) {
        quartzLogMapper.delete(keepDay);
    }
    
}